" Plugins
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#rc()
" let Vundle manage Vundle
" required!·
" git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Bundle 'VundleVim/Vundle.vim'
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'exvim/ex-matchit'
Plugin 'kien/ctrlp.vim'
Plugin 'majutsushi/tagbar'
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tpope/vim-fugitive'
Plugin 'pangloss/vim-javascript'
Plugin 'kchmck/vim-coffee-script'
Plugin 'hynek/vim-python-pep8-indent'
Plugin 'tell-k/vim-autopep8'
Plugin 'nvie/vim-flake8'
Plugin 'ervandew/supertab'
Plugin 'davidhalter/jedi-vim'
" Plugin 'Valloric/YouCompleteMe'
Plugin 'mattn/emmet-vim'
Plugin 'hail2u/vim-css3-syntax'
Plugin 'ap/vim-css-color'
Plugin 'jeetsukumaran/vim-buffergator'
Plugin 'tpope/vim-surround'
Plugin 'tomasr/molokai'
call vundle#end()
filetype plugin indent on
filetype plugin on

" Global settings
"set bg=dark
let mapleader = ","
filetype off
syntax on
set ai
set nu
set nocompatible
set tabstop=4
set shiftwidth=2
set expandtab
set t_Co=256
set laststatus=2
set noshowmode
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8,ucs-bom,chinese
set list listchars=tab:→\ ,trail:·
set autoread
set shortmess=at
set timeout timeoutlen=1000 ttimeoutlen=50
set hlsearch incsearch smartcase ignorecase
set completeopt=longest,menuone
set cot=menu
set wildignore+=*.o,*.log,*.obj,.git,*.jpg,*.png,*.gif,*/vendor/bundle,*/vendor/cache
cmap w!! w !sudo tee % > /dev/null
set title
set t_ts=
set titlestring=vim-%{split(getcwd(),'\/')[-1]}

" nmap <C-H> :CTRL-W h<CR>
" Preferences
" Tree
let mapleader=","
nmap <C-L> :NERDTreeToggle<CR>
let NERDTreeWinPos="right"
let NERDTreeIgnore=['*.pyc']
let NERDTreeShowHidden=1

" Tags & Search
map <silent> <F2> : !ctags -R --exclude=public --exclude=vendor .<CR>
nmap <F8> :TagbarToggle<CR>
let g:tagbar_left=1
let g:ctrlp_custom_ignore = {
  \ 'dir':  'vendor/bundle/*\|vendor/cache/*\|spec',
  \ 'file': '\v\.(exe|so|dll|swp|log|jpg|png|json)$',
  \ }
if executable("ack")
    nnoremap <leader>a :Ack
    let g:ackprg="ack -H --smart-case --nocolor --nogroup --column
          \ --nocss --ignore-dir=vendor --ignore-dir=log --ignore-dir=tmp
          \ --ignore-file=is:Session.vim --ignore-file=is:tags"
    let g:ackhighlight=1
endif

" StatusLine
let g:bufferline_echo = 1
let g:airline_powerline_fonts = 1
" let g:airline_theme='molokai'
let g:airline_theme='powerlineish'
let g:airline_symbols = {}
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.linenr = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.space = ' '
let g:airline_symbols.branch = '⎇'



" File types
autocmd BufNewFile,BufRead Thorfile set filetype=python
autocmd BufNewFile,BufRead *.thor set filetype=python
autocmd BufNewFile,BufRead Gemfile set filetype=python
autocmd BufNewFile,BufRead Capfile set filetype=python
autocmd BufNewFile,BufRead pryrc set filetype=python
autocmd BufNewFile,BufRead *.less set filetype=css
autocmd BufNewFile,BufRead *.god set filetype=python
autocmd BufNewFile,BufRead *.json set filetype=javascript
autocmd BufNewFile,BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:>
autocmd BufNewFile,BufRead *.coffee set filetype=coffee
autocmd FileType c,java,sh,python,html,javascript set ts=4 sw=4 sts=4 et

" Autopep8
let g:autopep8_max_line_length=100
autocmd FileType python map <buffer> <F9> :call Autopep8()<CR>
let g:autopep8_disable_show_diff=1
let g:PyFlakeDisabledMessages = 'E402'
let g:PyFlakeCheckers = 'pep8,mccabe,frosted'
let g:flake8_show_in_file = 1
let g:PyFlakeCWindow = 6
let g:PyFlakeOnWrite = 1
let g:flake8_show_in_gutter = 1
let g:syntastic_python_flake8_args='--ignore=E402'
autocmd! BufWritePost *.py call Flake8()
let g:PyFlakeDisabledMessages = 'E402,501'

" enable molokai
let g:molokai_original = 1
let g:rehash256 = 1

" 打开文件时始终跳转到上次光标所在位置
autocmd BufReadPost *
      \ if ! exists("g:leave_my_cursor_position_alone") |
      \     if line("'\"") > 0 && line ("'\"") <= line("$") |
      \         exe "normal g'\"" |
      \     endif |
      \ endif

" colorscheme delek


nnoremap <F5> "=strftime("%Y-%m-%d %H:%M:%S")<CR>P
inoremap <F4> <C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR>

"设置Esc键
map <F1> <Esc>
imap <F1> <Esc>
imap <C-g> <Esc>

" 调整split的尺寸
if bufwinnr(1)
 map = <C-W>+
 map - <C-W>-
 map } <C-W>><CR>
 map { <C-W><<CR>
endif

map td :tabnew .<cr>
map cd :tabclose <cr>

" 打开缓冲文件列表
nmap <C-x>b :BuffergatorOpen<cr>

" 保存文件与退出
map <C-x> :write<cr>
map <C-x>x :exit<CR>

" 光标移动
imap <C-k> <Up>
imap <C-j> <Down>
imap <C-h> <Left>
imap <C-l> <Right>
nmap <C-e> $
nmap <c-a> ^

" 全选
nmap <C-x>h ggvG$

" Add the virtualenv's site-packages to vim path
if has('python')
py << EOF
import os.path
import sys
import vim
if 'VIRTUAL_ENV' in os.environ:
    project_base_dir = os.environ['VIRTUAL_ENV']
    sys.path.insert(0, project_base_dir)
    activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
    execfile(activate_this, dict(__file__=activate_this))
EOF
endif

" Supertab configuration
let g:SuperTabDefaultCompletionType = "<c-n>"
let g:SuperTabContextDefaultCompletionType = "<c-n>"

" config jedi
let g:jedi#goto_definitions_command = "<leader>d"
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#documentation_command = "K"
